package com.bluelinelabs.conductor.demo.controllers.base;

import com.bluelinelabs.conductor.conductor.Controller;
import com.bluelinelabs.conductor.conductor.manager.ObjectManager;
import ohos.aafwk.content.IntentParams;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;


/**
 * lipeiquan
 *
 * @since 2021-05-06
 */
public abstract class BaseController extends RefWatchingController {
    public int layoutRes;
    public String title;


    public BaseController(int layoutRes) {
        super();
        this.layoutRes = layoutRes;
    }


    /**
     * Constructor that takes arguments that need to be retained across restarts.
     *
     * @param args Any arguments that need to be retained.
     */
    public BaseController(int layoutRes, IntentParams args) {
        super(args);
        this.layoutRes = layoutRes;
    }


    {
        addLifecycleListener(new LifecycleListener() {
            @Override
            public void postCreateView(Controller controller, Component component) {
                super.postCreateView(controller, component);
                onViewCreated(component);
                changeToolbarContent();
            }


        });
    }

    public void changeToolbarContent() {
        ObjectManager.getInstance().changeToolbarContent(title);
    }


    @Override
    public Component onCreateView(LayoutScatter inflater, ComponentContainer container, IntentParams savedViewState) {
        return inflater.parse(layoutRes, container, false);
    }

    public abstract void onViewCreated(Component component);


}
